﻿Ext.define('app.system.substance.Index',
{
    extend: 'Ext.grid.Panel',
    border: true,
    //title: '物质库',
    tbar: [],
    controller: 'substance',
    //viewModel: {
    //    type: 'compoundModel'
    //},
    requires: ['app.system.substance.SubstanceController'],
    viewConfig: {
        enableTextSelection: true //可以复制单元格文字
    },
    forceFit: false,
    multiColumnSort: true,
    initComponent: function () {
        var me = this;
        me.items = [];
        me.tbar = [
            {
                text: localize('Add'), iconCls: "add", handler: 'onAdd'
            },
            //{
            //    text: '编辑', iconCls: "edit", bind: { disabled: '{btnHidden}' }, handler: 'onEdit'
            //},
            //{
            //    text: '删除', iconCls: "delete", bind: { disabled: '{btnHidden}' }, handler: 'onRemove'
            //},
            "->",
            {
                xtype: 'textfield',
                width: 200,
                emptyText: '中文名、英文名、CAS',
                reference: 'txt_Search',
            },
            {
                text: '查询', iconCls: "search", handler: 'search'
            }
        ];
        me.store = Ext.create("app.ux.PagePrmStore", { url: '/api/services/app/substance/GetAll' });

        me.bbar = new Ext.toolbar.Paging({
            store: me.store,
            displayInfo: true,
            displayMsg: "显示{0}-{1}条,共计{2}条",
            emptyMsg: "没有数据"
        });
        me.callParent(arguments);
    },
    columns: [
         {
             xtype: 'actioncolumn',
             width: 50,
             header: localize('Operating'),
             items: [
             {
                 iconCls: 'edit',
                 tooltip: localize('Edit'),
                 handler: 'onEdit'
             }]
         },
                {
                    header: '结构式',
                    sortable: false,
                    dataIndex: 'molPngBase64'
                    , align: 'center',
                    renderer: function (value, p, record) {

                        if (value && value.length > 10) {
                            return '<img src="data:image/png;base64,' + value + '" onload="if(this.height >= 50||this.width >= 100){ if((this.height*2) >this.width) {this.height = 50}else {this.width=100}}" >'
                        }


                    }
                },
        { header: "CAS", dataIndex: 'cas' },
        { header: localize('ChineseName'), dataIndex: 'cnName' },
        { header: localize('EnglishName'), dataIndex: 'enName' },
        { header: localize('Formula'), dataIndex: 'formula' },
        { header: localize('MolecularWeight'), dataIndex: 'molecularWeight' },
        { header: localize('HighRisk'), dataIndex: 'highRisk' },
    ]
});
